package br.usp.ipq.extgwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.Field;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.form.Label;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.form.TimeField;
import com.gwtext.client.widgets.form.VType;
import com.gwtext.client.widgets.form.event.FieldListenerAdapter;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ExtGWTForm implements EntryPoint {

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		Panel panel = new Panel();
		panel.setBorder(false);
		panel.setPaddings(15);

		final FormPanel formPanel = new FormPanel();
		formPanel.setFrame(true);
		formPanel.setTitle("Simple Form");

		formPanel.setWidth(350);
		formPanel.setLabelWidth(75);
		formPanel.setUrl("/save-form");

		Label label = new Label();
		label.setHtml("<p>This is an example of a Form Label. This can have any <b>HTML</b> content.</p>");
		label.setCls("simple-form-label");
		label.setWidth(350);
		label.setHeight(20);

		final TextField firstName = new TextField("First Name", "first", 230);
		firstName.addListener(new FieldListenerAdapter() {
			public void onChange(Field self,Object newVal,Object oldVal) {
				Window.alert("Name Changed to '" + (String)newVal + "'");
			}
		});
		
		firstName.setAllowBlank(false);
		formPanel.add(firstName);

		final TextField lastName = new TextField("Last Name", "last", 230);
		formPanel.add(lastName);

		final TextField company = new TextField("Company", "company", 230);
		formPanel.add(company);

		final TextField email = new TextField("Email", "email", 230);
		email.setVtype(VType.EMAIL);
		formPanel.add(email);

		TimeField time = new TimeField("Time", "time", 230);
		time.setMinValue("8:00am");
		time.setMaxValue("6:00pm");
		formPanel.add(time);

		ButtonListenerAdapter saveListener = new ButtonListenerAdapter() {  
		    public void onClick(Button button, EventObject e) {  
		    	saveForm();
		    }
		};
		
		Button save = new Button("Save",saveListener);
		formPanel.addButton(save);

		Button cancel = new Button("Cancel");
		formPanel.addButton(cancel);

		panel.add(formPanel);

		RootPanel.get().add(panel);
	}
	public void saveForm() {
		//Null
	}
}
